<?php
 session_start();
 include 'db.php';
 include 'input.php';


 
 $username = $input->post('username');
 $password = $input->post('password');
 $re = $input->post('re');
//  var_dump($username,$password);
 if($username!=false && $password!=false){
     if($re!=false){
         setcookie("username",$username,time()+3600,'/');
         setcookie("password",$password,time()+3600,'/');
         setcookie("re",$re,time()+3600,'/');
     }
     $sql = "select * from user where username = '{$username}' and password = '{$password}'";
     $result = $conn->query($sql);
   
     if($result){
         if($row = $result->fetch_array(MYSQLI_ASSOC)){
             $_SESSION["username"] = $row['username'];
             header("Location:index.php");
         }
        
     }else{
         echo "用户名或密码错误";
     }
     
 }
 
 

?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录</title>
</head>
<body>
<form action="login.php" method="post">
        用户名:<input type="text" name="username" value="<?php echo $_COOKIE['username']?>"><br/>
         密码：<input type="password" name="password" value="<?php echo $_COOKIE['password']?>"><br/>
         <?php 
         if($_COOKIE['re']!=null){?>
                    记住密码: <input type="checkbox" name="re" value="1" checked="checked">
          <?php }else{?>
    	    记住密码: <input type="checkbox" name="re" value="1">
        <?php }?>
        
    
     <input type="submit" value="登录">
  </form>
  
 <form action="cnn/index.php" method="post" enctype="multipart/form-data">
 USERNAME:<input name="username"/><br/>
 <input type="checkbox" value="beijing" name="city[]"> 北京
 <input type="checkbox" value="jinan" name="city[]">济南
 <input type="checkbox" value="liaocheng" name="city[]"> 聊城<br/>
    上传文件：   <input type="file" name="upload"><br/>
     
   <input type="submit">
 </form>
  
</body>

</html>